#ifndef	__skeleton_H__
#define	__skeleton_H__

#include "rendVect.hpp"
#include "rendMaterial.hpp"

#include <string>
#include <vector>

namespace rend
{

struct Bone
{
	vect3			position;			// start position
	quat			orientation;		// start orientation
	vect3			scale;				// start scale
	uint8			parent_idx;			// 255 - no parent
	std::string		name;

	matx4			to_local;
	matx4			to_model;

	bool			matx_valid;
};


struct Track
{
	uint8 bone_idx;

	struct BonePositionKey
	{
		float		time;
		vect3		value;
	};

	struct BoneOrientationKey
	{
		float		time;
		quat		value;
	};

	struct BoneScaleKey
	{
		float		time;
		vect3		value;
	};

	std::vector< BonePositionKey >		position_key;
	std::vector< BoneOrientationKey >	orientation_key;
	std::vector< BoneScaleKey >			scale_key;

	mutable unsigned position_last_key_idx;
	mutable unsigned orientation_last_key_idx;
	mutable unsigned scale_last_key_idx;
};


bool
initBoneMatx(
	Material::EnvMat4v* bone_mat,
	Bone* bone,
	const unsigned bone_idx);


bool
updateBoneMatx(
	Material::EnvMat4v* bone_mat,
	Bone* bone,
	const unsigned bone_idx);


bool
invalidateBoneMatx(
	Bone* bone,
	const unsigned bone_idx,
	const unsigned num_invalid,
	const unsigned* invalid_idx);


void
animateSkeleton(
	Material::EnvMat4v* bone_mat,
	Bone* bone,
	const std::vector< Track >& skeletal_animation,
	const float anim_time);


void
resetSkeletonAnimProgress(
	const std::vector< Track >& skeletal_animation);


bool
loadSkeletonAnimationAge(
	Material::EnvMat4v* bone_mat,
	Bone* bone,
	std::vector< Track >& skeletal_animation,
	FILE* f);

} // namespace rend

#endif // __skeleton_H__
